import { defineStore } from "pinia";

export const useUserStore = defineStore("user", {
  state: () => ({
    token: localStorage.getItem("token") || "",
    role: localStorage.getItem("role") || "guest",
  }),
  actions: {
    setUser(token: string, role: string) {
      this.token = token;
      this.role = role;
      localStorage.setItem("token", token);
      localStorage.setItem("role", role);
    },
    logout() {
      this.token = "";
      this.role = "guest";
      localStorage.removeItem("token");
      localStorage.removeItem("role");
    },
  },
});
